package com.freedom.admin.infrastructure.persistence.repository;

import com.freedom.admin.domain.repository.SysDeptRepository;
import com.freedom.admin.infrastructure.persistence.assembler.DeptAssembler;
import com.freedom.admin.infrastructure.persistence.mapper.SysDeptMapper;
import com.freedom.admin.infrastructure.persistence.pojo.bo.DeptBO;
import com.freedom.admin.infrastructure.persistence.pojo.po.SysDeptPO;
import com.freedom.admin.infrastructure.persistence.pojo.query.DeptQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class SysDeptRepositoryImpl implements SysDeptRepository {

    private final SysDeptMapper deptMapper;

    private final DeptAssembler deptAssembler;

    @Override
    public List<DeptBO> listDept(DeptQuery queryParam) {
        List<SysDeptPO> sysDeptPOList = deptMapper.selectDeptList(queryParam);
        return deptAssembler.toBOList(sysDeptPOList);
    }

    @Override
    public DeptBO findById(Integer deptId) {
        SysDeptPO sysDeptPO = deptMapper.selectDeptById(deptId);
        return deptAssembler.toBO(sysDeptPO);
    }

    @Override
    public Boolean modifyDept(DeptBO deptBO) {
        SysDeptPO sysDeptPO = deptAssembler.toPO(deptBO);
        return deptMapper.updateDeptById(sysDeptPO);
    }

    @Override
    public Boolean addDept(DeptBO deptBO) {
        SysDeptPO sysDeptPO = deptAssembler.toPO(deptBO);
        return deptMapper.insertDept(sysDeptPO);
    }

    @Override
    public void removeDept(List<Integer> ids) {
        deptMapper.deleteByIds(ids);
    }
}
